package com.leo.biz.service.datacenter;

import com.leo.biz.po.DailyKRecord;
import com.leo.biz.service.pub.DaoCenter;
import com.leo.biz.service.pub.SIC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * Created by leo on 2016/8/6.
 */
@Service
public class CommServiceImpl {

    @Autowired
    private DaoCenter daoCenter;

    /*获取A股交易日*/
    public List<Integer> getTradeDays(int beg,int end)
    {
        List<DailyKRecord> _list=daoCenter.queryResult(DailyKRecord.class, " where stockno='000001' and cldate>="+beg+" and cldate<= "+end+" order by cldate asc");
        List<Integer> ret=new LinkedList<>();
        for(int i=0;i<_list.size();i++)
        {
            ret.add(_list.get(i).getCldate());
        }
        return ret;
    }

    public List<DailyKRecord> getDayKList(String stockno,int beg,int end)
    {
        List<DailyKRecord> _list=daoCenter.queryResult(DailyKRecord.class, " where stockno='"+stockno+"' and cldate>="+beg+" and cldate<= "+end+" order by cldate asc");
        return  _list;
    }


    public List<Float> getDayKMa(String stockno,int beg,int end,int daynum)
    {
        List<DailyKRecord> _list=daoCenter.queryResult(DailyKRecord.class, " where stockno='"+stockno+"' and cldate>="+beg+" and cldate<= "+end+" order by cldate asc");
        List<Float> _endpList=new LinkedList<>();
        for (int i=0;i<_list.size();i++)
        {
            _endpList.add(_list.get(i).getEndp());
        }
        return  SIC.MA(_endpList,daynum);
    }

    public  Object getDayKAll(String stockno,int beg,int end)
    {
        Map<String,Object> ret=new HashMap<>();
        List<DailyKRecord> _temp=getDayKList(stockno,beg,end);
        List<String[]>_kList=new LinkedList<>();
        for(DailyKRecord t : _temp)
        {

            String[] rec=new String[5];
            rec[0]=t.getCldate().toString();
            rec[1]=t.getBegp().toString();
            rec[2]=t.getEndp().toString();
            rec[3]=t.getMinp().toString();
            rec[4]=t.getMaxp().toString();
            _kList.add(rec);

        }

        return _kList;
    }

}
